package FIT::Test;

use strict;
use warnings;
use Module::Compile -base;
use aliased 'FIT::Module::Compiler';

sub pmc_compile {
    my ($class, $src, $extra_info) = @_;

    # take the class under test from the 'use' line
    my $package = __PACKAGE__;
    my $class_under_test = $extra_info->{use};
    $class_under_test =~ s/^\s*use\s+$package\s*//;
    my $has_class_under_test = $class_under_test =~ /\w/;
    my $prefix = '';
    if ($has_class_under_test) {
        $class_under_test =~ s/[^\w:]//g;
        $prefix = "sub IUT { '$class_under_test' }";
    }
    my $compiled_output = Compiler->compile(
        src    => $src,
        prefix => $prefix,
        use    => [
            qw(Test::More Test::Exception),
            q{IO::All -utf8},
            ($has_class_under_test? $class_under_test: ()),
            q{base 'Test::Class'},
        ],
    );

    return $compiled_output;
}

1;
